
<template>
	<el-main>
		<el-row :gutter="15">
			<el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24" v-for="item in list" :key="item.id">
				<el-card class="matrix matrix-item" shadow="hover">
					<h2>{{item.name}}</h2>
					<ul>
						<li>
							<h4>矩阵描述</h4>
							<p>{{item.description}}</p>
						</li>
					</ul>
					<div class="bottom">
						<div class="state">
						</div>
						<div class="handler">
							<el-tooltip  content="编辑矩阵基本信息" placement="bottom" >
								<el-button type="primary" icon="el-icon-edit" size="small" circle @click="edit(item)"></el-button>
							</el-tooltip>
							<el-tooltip  content="编辑列信息" placement="bottom" >
								<el-button type="primary" icon="el-icon-dataAnalysis" size="small" circle @click="columnEdit(item)"></el-button>
							</el-tooltip>
							<el-tooltip  content="编辑矩阵数据" placement="bottom" >
								<el-button type="primary" icon="el-icon-tickets" size="small" circle @click="dataEdit(item)"></el-button>
							</el-tooltip>
						</div>
					</div>
				</el-card>
			</el-col>
			<el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24" v-auth="'system.matrix.add'">
				<el-card class="matrix matrix-add" shadow="never" @click="add">
					<el-icon><el-icon-plus /></el-icon>
					<p>添加矩阵</p>
				</el-card>
			</el-col>
		</el-row>
	</el-main>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
	<column-edit v-if="columnDialog.save" ref="columnDialog" @success="handleSuccess" @closed="columnDialog.save=false"></column-edit>
	<data-edit v-if="dataDialog.save" ref="dataDialog" @success="handleSuccess" @closed="dataDialog.save=false"></data-edit>
</template>

<script>
	import saveDialog from './save'
	import ColumnEdit from "@/views/system/setting/matrix-manage/columnEdit";
	import DataEdit from "@/views/system/setting/matrix-manage/dataEdit";

	export default {
		name: 'matrix-manage',
		components: {
			DataEdit,
			ColumnEdit,
			saveDialog
		},
		provide() {
			return {
				list: this.list
			}
		},
		data() {
			return {
				dialog: {
					save: false,
					logsVisible: false
				},
				columnDialog: {
					save: false,
					logsVisible: false
				},
				dataDialog: {
					save: false,
					logsVisible: false
				},
				list: [
				]
			}
		},
		mounted() {
			this.getList();
		},
		methods: {
			async getList(){
				var res = await this.$API.system.matrix.listAll.get();
				if(res.success){
					this.list = res.data;
				}
			},
			add(){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open()
				})
			},
			edit(matrix){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('edit').setData(matrix)
				})
			},
			async columnEdit(matrix){
				var res = await this.$API.system.matrixColumn.getByMatrix.get(matrix.id);
				if(res.success){
					this.columnDialog.save = true
					this.$nextTick(() => {
						this.$refs.columnDialog.open().setData(res.data)
					})
				}
			},
			async dataEdit(matrix){
				//获取列信息 获取表数据
				var res = await this.$API.system.matrixData.getByMatrix.get(matrix.id);
				if(res.success){
					this.dataDialog.save = true
					this.$nextTick(() => {
						this.$refs.dataDialog.open().setData(res.data)
					})
				}
			},
			//本地更新数据
			handleSuccess(){
				this.getList();
			}
		}
	}
</script>

<style scoped>
	.matrix {height: 250px; position: relative;}
	.matrix-item h2 {font-size: 15px;color: #3c4a54;padding-bottom:15px;}
	.matrix-item li {list-style-type:none;margin-bottom: 10px;}
	.matrix-item li h4 {font-size: 12px;font-weight: normal;color: #999;}
	.matrix-item li p {margin-top: 5px;}
	.matrix-item .bottom {
		border-top: 1px solid #EBEEF5;
		text-align: right;
		padding-top:10px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: absolute;
		bottom: 10px;
		padding-right: 40px;
		width: 100%;
	}
	.matrix-add {display: flex;flex-direction: column;align-items: center;justify-content: center;text-align: center;cursor: pointer;color: #999;}
	.matrix-add:hover {color: #5A55E4;}
	.matrix-add i {font-size: 30px;}
	.matrix-add p {font-size: 12px;margin-top: 20px;}
</style>
